<?php
/**
 *
 * User: Jessica@aweb.wang
 * Date: 2023/3/10 14:50
 * Email: <1194323013@qq.com>
 *                            _ooOoo_
 *                           o8888888o
 *                           88" . "88
 *                           (| -_- |)
 *                           O\  =  /O
 *                        ____/`---'\____
 *                      .'  \\|     |//  `.
 *                     /  \\|||  :  |||//  \
 *                    /  _||||| -:- |||||-  \
 *                    |   | \\\  -  /// |   |
 *                    | \_|  ''\---/''  |   |
 *                    \  .-\__  `-`  ___/-. /
 *                  ___`. .'  /--.--\  `. . __
 *               ."" '<  `.___\_<|>_/___.'  >'"".
 *              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *              \  \ `-.   \_ __\ /__ _/   .-` /  /
 *         ======`-.____`-.___\_____/___.-`____.-'======
 *                            `=---='
 *        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *                      Buddha Bless, No Bug !
 **/

namespace app\common\service;

use app\common\model\Applet;
use app\common\utils\TreeUtils;

class PremiseService
{
    public function list(){
        $where[]=['isdel','=',0];
        $listdata=Applet::field('id,name')->with(['premise' => function($query){
            $query->where('isdel',0)->field('id,pid,name,applet_id');
        }])->where($where)->select();

        $listdataArray=$listdata->toArray();
        foreach ($listdataArray as $key=>$value) {
            $listdataArray[$key]['premise']=TreeUtils::sort($value['premise']);
        }
        return $listdataArray;
    }
}